using System;
using System.Diagnostics;

namespace PopMail
{
    public class POP3Credentials : IPOP3Credentials
    {
        private string _user;
        private string _password;
        private string _server;
        private int _port;

        /// <summary>
        /// POP3 Credentials constructor object
        /// </summary>
        public POP3Credentials(string host, int port, string userName, string password)
        {
            //this._user = System.Configuration.ConfigurationManager.AppSettings["Pop3User"].ToString();
            //this._password = System.Configuration.ConfigurationManager.AppSettings["Pop3Pass"].ToString();
            //this._server = System.Configuration.ConfigurationManager.AppSettings["Pop3Server"].ToString();
            //this._port = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["Pop3Port"].ToString());

            this._user = userName;
            this._password = password;
            this._server = host;
            this._port = port;
        }

        /// <summary>
        /// User
        /// </summary>
        public string User
        {
            get { return _user; }
        }

        /// <summary>
        /// Password
        /// </summary>
        public string Password
        {
            get { return _password; }
        }

        /// <summary>
        /// Server
        /// </summary>
        public string Server
        {
            get { return _server; }
        }

        /// <summary>
        /// Pop3 port
        /// </summary>
        public int Port
        {
            get { return _port; }
        }

        /// <summary>
        /// Method to assert credentials
        /// </summary>
        /// <returns></returns>
        public bool AssertCredentials()
        {
            int status = 0;

            if (this._user == null)
            {
                Trace.WriteLine("Username is invalid or null");
                status++ ;
            }

            if (this._password == null)
            {
                Trace.WriteLine("Password is invalid or null");
                status++;
            }

            if (this._server == null)
            {
                Trace.WriteLine("Servername is invalid or null");
                status++;
            }

            if (this._port == 0)
            {
                Trace.WriteLine("Port No. is invalid or null");
                status++;
            }

            if (status >= 1)
            {
                return false;
            }
            else
            {
                return true;
            }
        }
    }
}
